package com.wxprogram.smallprogram.controller;

import com.wxprogram.smallprogram.entity.FindStudent;
import com.wxprogram.smallprogram.entity.FindTeacher;
import com.wxprogram.smallprogram.entity.utilEntity.PageUtil;
import com.wxprogram.smallprogram.service.SaveService;
import com.wxprogram.smallprogram.util.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/save")
public class SaveController {
    @Autowired
    private SaveService saveService;

    @RequestMapping("/student")
    public JSON studentSave(@RequestParam("openID")String openID,@RequestParam("code")int code,@RequestParam("isSave")int isSave){

        int rs = saveService.studentSave(openID,code,isSave);

        if(rs > 0){
            return JSON.ok("success");
        }else {
            return JSON.error("failure");
        }
    }

    @RequestMapping("/stsave")
    public PageUtil<FindStudent> getStudentSave(@RequestParam("openID")String openID,@RequestParam(name = "current",required = false,defaultValue = "1")int current){

        return saveService.getStudentSaveList(openID,current);
    }

    @RequestMapping("/teacher")
    public JSON teacherSave(@RequestParam("openID")String openID,@RequestParam("code")int code,@RequestParam("isSave")int isSave){
        int rs = saveService.teacherSave(openID,code,isSave);

        if(rs > 0){
            return JSON.ok("success");
        }else {
            return JSON.error("failure");
        }
    }

    @RequestMapping("/trsave")
    public PageUtil<FindTeacher> getTeacherSave(@RequestParam("openID")String openID,@RequestParam(name = "current",required = false,defaultValue = "1")int current){

        return saveService.getTeacherSaveList(openID,current);
    }


}
